package com.hmall.controller;

import com.hdmall.business.common.annotation.LoginRequired;
import com.hdmall.business.common.common.ServerResponse;
import com.hmall.model.MallDealer;
import com.hmall.model.SysUser;
import com.hmall.service.MerchandiserService;
import com.hmall.util.TokenUtil;
import com.hmall.vo.MerchaCheckVo;
import com.hmall.vo.MerchaFilterVo;
import com.hmall.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import redis.clients.jedis.JedisPool;
import java.util.List;

/**
 * @ClassName MerchandiserController
 * @Description // 有关跟单员的接口
 * @Author zhoutao
 * @Date 2018/10/13 11:23
 * @Version 2.0
 **/

@RestController
@Api(value = "跟单员接口API", description = "跟单员API说明")
@RequestMapping("/mercha/")
public class MerchandiserController {


    @Autowired
    MerchandiserService merchandiserService;

    @Autowired
    JedisPool jedisPool;

    TokenUtil tokenUtil = new TokenUtil();
    /**
     * @Author zhoutao
     * @Description // 筛选条件
     * @Date 2018/10/13 11:24
     * @Param
     * @return
     **/
    @LoginRequired
    @GetMapping("getOrderFilter")
    @ApiOperation(value = "得到订单的删选条件以及数目", notes = "2018/10/16支持资金和跟单员共用")
    public ServerResponse<List<MerchaFilterVo>> getOrderFilter(String token, Integer dealerId) throws Exception {

        SysUser user = tokenUtil.tokenToUser(jedisPool, token).getData();
        return merchandiserService.getOrderFilter(user.getUserId(), dealerId);
    }

    /**
     * @Author zhoutao
     * @Description //办事处列表
     * @Date 2018/10/13 11:25
     * @Param
     * @return
     **/
    @LoginRequired
    @GetMapping("getDealerList")
    @ApiOperation(value = "得到办事处列表")
    public  ServerResponse<List<MallDealer>> getDealerList(String token) throws Exception {

        SysUser user = tokenUtil.tokenToUser(jedisPool, token).getData();
        return merchandiserService.getDealerList(user.getUserId());
    }

    /**
     * @Author zhoutao
     * @Description // 订单列表
     * @Date 2018/10/13 11:25
     * @Param  
     * @return 
     **/
    @LoginRequired
    @GetMapping("getOrderList")
    @ApiOperation(value = "得到订单列表", notes = "2018/10/16支持资金调用")
    public ServerResponse<PageVo> getOrderList(String token, Integer dealerId, String roleStatus, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) throws Exception {

        SysUser user = tokenUtil.tokenToUser(jedisPool, token).getData();
        return merchandiserService.getOrderList(user.getUserId(), dealerId, roleStatus, pageNum, pageSize);
    }


    /**
     * @Author zhoutao
     * @Description // 审核订单
     * @Date 2018/10/13 12:38
     * @Param
     * @return
     **/
    @LoginRequired
    @PostMapping("examOrder")
    @ApiOperation(value = "审核订单", notes = "支持跟单员和资金管理员调用同一接口， 1表示审核通过 2表示审核不通过" + "\n\njsonStr说明\n" +
            "\n" + "\tInteger productId\n" + "\n" + "\tBigDecimal price\n" +
            "\n" + "\tString grade\n" + "\n" + "\tBigDecimal weight\n")
    public ServerResponse<MerchaCheckVo> examOrder(String token, Long orderNo, String jsonOrderItemStr, Integer status, String opinion, String sendDate) throws Exception {


        SysUser user = tokenUtil.tokenToUser(jedisPool, token).getData();
        return merchandiserService.examOrder(user.getUserId(), orderNo, jsonOrderItemStr, status, opinion, sendDate, null);
    }


    /**
     * @Author zhoutao
     * @Description // 判断是否可以通过审核
     * @Date 2018/10/15 17:28
     * @Param [token, orderNo]
     * @return com.hmall.common.ServerResponse
     **/
    @LoginRequired
    @GetMapping("checkPassExam")
    @ApiOperation(value = "判断跟单员是否可以通过审核")
    public ServerResponse checkPassExam(String token, Long orderNo) throws Exception {

        SysUser user = tokenUtil.tokenToUser(jedisPool, token).getData();
        return merchandiserService.checkPassExam(user.getUserId(), orderNo);
    }
    @LoginRequired
    @ApiOperation(value = "跟单员给资金管理员发送提醒事项")
    @PostMapping("remindFinance")
    public ServerResponse remindFinance(String token, Long orderNo) throws Exception {

        SysUser user = tokenUtil.tokenToUser(jedisPool, token).getData();
        return merchandiserService.remindFinance(user.getUserId(), orderNo);
    }
    @LoginRequired
    @Deprecated
    @ApiOperation(value = "业务员给跟单员和资金管理员发送提醒事项")
    @PostMapping("remindSubmitOrder")
    public ServerResponse remindSubmitOrder(String token, Long orderNo){

        return null;
    }
}
